﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace FluentResourceMapping
{
    public class FluentResourceMappingContainer
    {
        private readonly IList<Assembly> assemblies = new List<Assembly>();
        private readonly List<Type> types = new List<Type>();

        public FluentResourceMappingContainer Add(Type type)
        {
            types.Add(type);
            return this;
        }

        public FluentResourceMappingContainer Add<T>()
        {
            return Add(typeof (T));
        }

        public FluentResourceMappingContainer AddFromAssembly(Assembly assembly)
        {
            assemblies.Add(assembly);
            return this;
        }

        public FluentResourceMappingContainer AddFromAssemblyOf<T>()
        {
            return AddFromAssembly(typeof (T).Assembly);
        }

        public void Apply(ResourceMappingModel resourceMappingModel)
        {
            foreach (Assembly assembly in assemblies)
            {
                resourceMappingModel.AddMappingsFromAssembly(assembly);
            }

            foreach (Type type in types)
            {
                resourceMappingModel.AddMapping(type);
            }
        }
    }
}